﻿using System.Collections.Generic;
using System.Linq;
 
using AmazeUI.db;
using AmazeUI.Imodel;

namespace AmazeUI.bll
{
    /// <summary>
    ///评论
    /// </summary>
    public class ArticleBll : BaseBll
    {
        /// <summary>
        /// 发表评论
        /// </summary>
        /// <param name="model"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public int AddArticleComment(IArticleComment model, int parentId = 0)
        {

            var comment = new ArticleComment(model);
            comment.ParentId = parentId;
            var articleComment = this.db.ArticleComment.Add(comment);
            this.db.SaveChanges();
            return articleComment.Id;
        }
        /// <summary>
        /// 获取文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Article  GetArticleModel(int id)
        {
            return this.db.Article.Find(id);
            
        }

        public int AddArticle(IArticle model)
        {
            var article = new Article(model);
            this.db.Article.Add(article);
            this.db.SaveChanges();
            return article.Id;
        }
        /// <summary>
        /// LIST
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Article > GetArticleList()
        {
            return   this.db.Article.ToList();
            
        }
    }
}